import { reactive, toRefs } from "vue"
import { toHump } from "@/utils/stringFun"
import { getDictApi } from "@/api/dicts"

/**
 * 获取字典数据
 */
export function useDict(...args: any[]) {
  const res = reactive({} as any)
  return (() => {
    args.forEach((dictType) => {
      res[dictType] = [] //下划线
      res[toHump(dictType)] = [] //驼峰
      getDictApi(dictType).then((resDict: any) => {
        res[dictType] = resDict.data
        res[toHump(dictType)] = resDict.data
      })
    })
    return toRefs(res)
  })()
}
